﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

using UnityEngine;

namespace Assets.Scripts.Tcp
{
    /// <summary>
    /// 断言
    /// </summary>
    [System.Diagnostics.DebuggerStepThrough]
    public static class AssertThat
    {
        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsFalse(
            bool actual,
            string message,
            [CallerFilePath] string file = null,
            [CallerMemberName] string member = null,
            [CallerLineNumber] int line = 0)
        {
            if (actual != false)
            {
                Debug.LogErrorFormat("发生异常：{0}\r\n\t在文件：{1}\r\n\t在方法：{2}\r\n\t在行：{3}", message, file, member, line);
            }
        }

        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsTrue(
            bool actual,
            string message,
            [CallerFilePath] string file = null,
            [CallerMemberName] string member = null,
            [CallerLineNumber] int line = 0)
        {
            if (actual) return;

            Debug.LogErrorFormat("发生异常：{0}\r\n\t在文件：{1}\r\n\t在方法：{2}\r\n\t在行：{3}", message, file, member, line);
        }

        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsNotNull(
            object actual,
            string message,
            [CallerFilePath] string file = null,
            [CallerMemberName] string member = null,
            [CallerLineNumber] int line = 0)
        {
            IsTrue(actual != null, message, file, member, line);
        }
        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsNull(
           object actual,
           string message,
           [CallerFilePath] string file = null,
           [CallerMemberName] string member = null,
           [CallerLineNumber] int line = 0)
        {
            IsTrue(actual == null, message, file, member, line);
        }

        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsNotNullOrEmpty(
            string actual,
            string message,
            [CallerFilePath] string file = null,
            [CallerMemberName] string member = null,
            [CallerLineNumber] int line = 0)
        {
            IsTrue(!string.IsNullOrEmpty(actual), message, file, member, line);
        }

        /// <param name="actual">真实值</param>
        /// <param name="message">断言失败的时候显示的消息</param>
        public static void IsEqual(
            object a,
            object b,
            string message,
            [CallerFilePath] string file = null,
            [CallerMemberName] string member = null,
            [CallerLineNumber] int line = 0)
        {
            IsTrue(a.Equals(b), message, file, member, line);
        }
    }
}
